﻿using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
using System.Windows.Forms;

namespace Swsk33.ArcMapDevelop
{
	public class GetLayerType : ICommand
	{
		/// <summary>
		/// ArcMap钩子对象
		/// </summary>
		private IApplication arcmapObject;

		public int Bitmap
		{
			get;
			set;
		}

		public string Caption
		{
			get { return "显示矢量图层类型"; }
		}

		public string Category
		{
			get { return "swsk33"; }
		}

		public bool Checked
		{
			get { return false; }
		}

		public bool Enabled
		{
			get { return true; }
		}

		public int HelpContextID
		{
			get;
			set;
		}

		public string HelpFile
		{
			get;
			set;
		}

		public string Message
		{
			get { return "显示矢量图层类型"; }
		}

		public string Name
		{
			get { return "显示矢量图层类型"; }
		}

		public void OnClick()
		{
			IMxDocument mxDocument = (IMxDocument)arcmapObject.Document;
			IMap map = mxDocument.FocusMap;
			for (int i = 0; i < map.LayerCount; i++)
			{
				ILayer layer = map.get_Layer(i);
				if (layer is IFeatureLayer)
				{
					IFeatureLayer featureLayer = (IFeatureLayer)layer;
					esriGeometryType type = featureLayer.FeatureClass.ShapeType;
					string msg;
					switch (type)
					{
						case esriGeometryType.esriGeometryPoint:
							msg = layer.Name + "是点类型。";
							break;
						case esriGeometryType.esriGeometryLine:
							msg = layer.Name + "是线类型。";
							break;
						case esriGeometryType.esriGeometryPolygon:
							msg = layer.Name + "是面类型。";
							break;
						default:
							msg = layer.Name + "未知类型。";
							break;
					}
					MessageBox.Show(msg);
				}
			}
		}

		public void OnCreate(object Hook)
		{
			arcmapObject = (IApplication)Hook;
		}

		public string Tooltip
		{
			get { return "显示矢量图层类型"; }
		}
	}
}